﻿public class Retful
{
    private Retful()
    {

    }

    /// <summary>
    /// Success：Code = 1
    /// Fail：Code = -1
    /// </summary>
    public int Code { get; set; }

    public string Msg { set; get; }

    public dynamic Value { get; set; }

    /// <summary>
    ///  Code = -1
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="para"></param>
    /// <returns></returns>
    public static Retful CreateFail(string msg, dynamic para = null)
    {
        return new Retful()
        {
            Code = -1,
            Msg = msg,
            Value = para
        };
    }


    /// <summary>
    /// Code = 1
    /// </summary>
    /// <param name="para"></param>
    /// <returns></returns>
    public static Retful CreateSuccess(dynamic para = null, string msg = null)
    {
        return new Retful()
        {
            Code = 1,
            Msg = msg,
            Value = para

        };
    }

    /// <summary>
    ///  Code = 自定义
    /// </summary>
    /// <param name="code"></param>
    /// <param name="msg"></param>
    /// <param name="para"></param>
    /// <returns></returns>
    public static Retful CreateRetful(int code, string msg, dynamic para = null)
    {
        return new Retful()
        {
            Code = code,
            Msg = msg,
            Value = para

        };
    }

    public override string ToString()
    {
        //转为Json
        return base.ToString();
    }
}